home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / devel / msqllib / e / simple.e < prev   
Text File  |  1999-01-01  |  2KB  |  77 lines

  1. OPT OSVERSION=37
  2. OPT PREPROCESS,REG=5
  3.  
  4. /*
  5.      msql.library simple example
  6.      ©1998 Christophe Sollet (cfc@iname.com)
  7.      AmigaE version by Piotr Gapinski (narg@polbox.com)
  8.  
  9.      This simple example list existing database and tables on
  10.      a mSQL database engine running on the local host.
  11. */
  12.  
  13.  
  14. MODULE 'msql','libraries/msql'
  15.  
  16. PROC main() HANDLE
  17.   DEF co=NIL:PTR TO msqlConnection,
  18.       mre:PTR TO m_result,mre2:PTR TO m_result,
  19.       mro:PTR TO m_row,mro2:PTR TO m_row
  20.   DEF a
  21.  
  22.   a:=msqlTypeNames(1)
  23.   WriteF('\s\n',a)
  24.   ->- open the library
  25.   ->-
  26.   IF (msqlbase:=OpenLibrary('msql.library',4))=NIL THEN Raise('OpenLibrary failed')
  27.  
  28.   ->- before doing any msql operation,
  29.   ->- we need a valid MsqlConnection structure
  30.   ->-
  31.   IF (co:=MsqlAllocConnection())=NIL THEN Raise('MsqlAllocConnection failed')
  32.  
  33.   ->- now we'll attempt a connection
  34.   ->- on a local mSQL database engine
  35.   ->-
  36.   IF (MsqlConnect(co,'localhost'))=NIL THEN Raise('MsqlConnect failed')
  37.  
  38.   ->- gets current DB list
  39.   ->-
  40.   IF (mre:=MsqlListDBs(co))=NIL THEN Raise('MsqlListDBs failed')
  41.   WriteF('DB(s):\n')
  42.  
  43.   ->- now display DB list
  44.   ->-
  45.   WHILE (mro:=MsqlFetchRow(mre))
  46.     WriteF('\s\n',mro.m_row)
  47.  
  48.     ->- for each DB, list tables
  49.     ->-
  50.     IF (MsqlSelectDB(co,mro.m_row))<>(-1)
  51.       IF (mre2:=MsqlListTables(co))
  52.         WriteF('\tTable(s):\n')
  53.  
  54.         ->- now display table list
  55.         ->-
  56.         WHILE mro2:=MsqlFetchRow(mre2) DO WriteF('\t\s\n',mro2.m_row)
  57.         MsqlFreeResult(mre2)
  58.       ENDIF
  59.     ELSE
  60.       MsqlFreeResult(mre)
  61.       Raise('SelectDB failed')
  62.     ENDIF
  63.   ENDWHILE
  64.   MsqlFreeResult(mre)
  65.  
  66. EXCEPT DO
  67.   IF (exception)
  68.     WriteF('\s\n',exception)
  69.     IF (co) THEN WriteF('\s\n',MsqlGetErrMsg(co))
  70.   ENDIF
  71.   IF (co)
  72.     MsqlClose(co)
  73.     MsqlFreeConnection(co)
  74.   ENDIF
  75.   IF (msqlbase) THEN CloseLibrary(msqlbase)
  76. ENDPROC
  77.